﻿using Lonewolf.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Lonewolf.IService
{
    /// <summary>
    /// 数据接口类
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public partial interface IBaseService<T> where T : class
    {
        /// <summary>
        /// 根据实体逻辑（软）删除
        /// </summary>
        /// <param name="entity">实体</param>
        void DeleteForge(T entity);
        /// <summary>
        /// 根据条件逻辑删除
        /// </summary>
        /// <typeparam name="T">实体</typeparam>
        /// <param name="express">拼接查询条件</param>
        /// <returns></returns>
        void DeleteForge(Expression<Func<T, bool>> express);
        /// <summary>
        /// 物理删除|无返回值
        /// </summary>
        /// <param name="entity">实体</param>
        void Delete(T entity);
        /// <summary>
        /// 物理删除|无返回值
        /// </summary>
        /// <param name="express">拼接条件</param>
        /// <param name="isDelete">是否过滤已经软删除的数据</param>
        void Delete(Expression<Func<T, bool>> express,bool isDelete=true);
        /// <summary>
        /// 查询对象|返回IQueryable
        /// </summary>
        /// <param name="isFilter">是否过滤已执行伪删除的数据，默认为true:过滤</param>
        /// <returns></returns>
        IQueryable<T> Query(bool isFilter = true);
        IQueryable<T> QueryNoTracking(bool isFilter = true);
        /// <summary>
        /// 新增数据|主键Id已经自动添加|返回String
        /// </summary>
        /// <param name="model">实体</param>
        /// <returns></returns>
        string Insert(T model);
        /// <summary>
        /// 异步新增数据
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<string> InsertAsync(T entity);
        /// <summary>
        /// 批量添加数据
        /// </summary>
        /// <param name="entities">实体列表</param>
        void InsertRange(IEnumerable<T> entities);
        /// <summary>
        /// 根据实体修改数据（更新全部字段）
        /// </summary>
        /// <param name="model">实体</param>
        void Update(T model);
        /// <summary>
        /// 附加形式修改数据
        /// 调用本方法前需要给实体的主键赋值，调用本方法后再给需要修改的字段赋值
        /// </summary>
        /// <param name="model">已赋值主键值的实体</param>
        void UpdateAttach(T model);
        
        /// <summary>
        /// 最终提交保存数据
        /// </summary>
        /// <returns></returns>
        bool SaveChanges();
        /// <summary>
        /// 异步操作最终保存
        /// </summary>
        /// <returns></returns>
        Task<bool> SaveChangesAsync();

    }
}
